package com.four.commodity.controller;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.four.commodity.service.CommodityService;
import com.four.commodity.service.impl.CommodityServiceImpl;
@WebServlet("/addCommodity.do")
public class AddCommodityServiet extends HttpServlet{

	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		this.doPost(req, resp);
	}
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		req.setCharacterEncoding("utf-8");
		resp.setCharacterEncoding("UTF-8");
		String id = req.getParameter("id");
		String name = req.getParameter("name");
		String producing_area = req.getParameter("producing_area");
		String descrption = req.getParameter("descrption");
		String create_time = req.getParameter("create_time");
		String market_price = req.getParameter("market_price");
		String product_amount = req.getParameter("product_amount");
		String picture = req.getParameter("picture");
		String discount = req.getParameter("discount");
	    String flag = req.getParameter("flag");
		CommodityService service = new CommodityServiceImpl();
		boolean result = service.addCommodity(id,name,producing_area,descrption,create_time,market_price,product_amount,picture,discount,flag);
		System.out.println("添加结果： " + result);
		req.getRequestDispatcher("view/index.html").forward(req, resp);
	}
}
